﻿using UnityEngine;
using System.Collections;
using FairyGUI;

namespace Baiyy {
	namespace Controls {
		/// <summary>
		/// 基础窗口
		/// </summary>
		public class BaseWindow {

			#region vars
			private GComponent _uiComp;
            #endregion

            #region getter&setter
            public GComponent contentView { get { return _uiComp;  } }
            #endregion

            #region methods

            public BaseWindow(string pkgName, string resName) {
				_uiComp = UIPackage.CreateObject(pkgName, resName).asCom;
			}

			/// <summary>
			/// 将组件添加到指定组件。
			/// </summary>
			/// <param name="parent">Parent.</param>
			public void Attach(GComponent parent) {
				parent.AddChild (_uiComp);
			}

			#endregion

			#region virtuals

			/// <summary>
			/// 销毁组件
			/// </summary>
			/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="BaseWindow"/>. The <see cref="Dispose"/>
			/// method leaves the <see cref="BaseWindow"/> in an unusable state. After calling <see cref="Dispose"/>, you must
			/// release all references to the <see cref="BaseWindow"/> so the garbage collector can reclaim the memory that the
			/// <see cref="BaseWindow"/> was occupying.</remarks>
			public virtual void Dispose() {
				_uiComp.RemoveFromParent ();
				_uiComp.Dispose ();
			}

			#endregion
		}
	}
}
